package com.yuxin.core;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author zehui.zeng
 * @date 13-4-16 下午8:28
 */
public class TransactionManager {
    Connection connection = null;
    boolean hasTransaction = false;

    public TransactionManager(Connection connection) {
        this.connection = connection;
    }

    public void begin() throws Exception {
        hasTransaction = true;
        connection.setAutoCommit(false);
        connection.setReadOnly(false);
    }

    public void commit() throws SQLException {
        if(hasTransaction){
            connection.commit();
        }
    }

    public void rollback() throws SQLException {
        if(hasTransaction){
            connection.rollback();
        }
    }


}
